﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ClassLibrary.Data;
using System.Data;
using ClassLibrary.Entity;

namespace ClassLibrary.DAO
{
    public  class TblPhoneBranDAO
    {
         private DBService _db = null;
         public TblPhoneBranDAO(string ConnectionString)
        {
            _db = new DBService(ConnectionString);
        }
        public DataTable InUpPhoneBrand(TblPhoneBrand phoneBrand, int mode)
        {
            DataTable flag = null;
            try
            {
                flag = _db.ExeSP_DataTable("TblPhoneBrand_InUp",
                    new string[] {"@IDPhoneBrand", "@PhoneBrandName", "@Mode"},
                    new object[] {phoneBrand.IDPhoneBrand, phoneBrand.PhoneBrandName,  mode}, CommandType.StoredProcedure);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return flag;
        }

        public DataTable GetIDBrand(int IDBrand)
        {
            DataTable phoneBrand = null;
            try
            {                 
                phoneBrand = _db.ExeSP_DataTable("select * from TblBrandPhone where IDBrand=@IDBrand",
                    new string[] { "@IDBrand" },
                    new object[] { IDBrand }
                    , CommandType.Text);
               
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return phoneBrand;
        }

        public bool check_phonebrand(string brandname)
        {
            bool flag = false;
            try
            {
                DataTable dt = _db.ExeSP_DataTable("select * from TblBrandPhone where BrandName = @BrandName",
                   new string[] { "@BrandName" },
                   new object[] { brandname },
                   CommandType.Text);
                if (dt.Rows.Count > 0)
                {
                    flag = true;
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return flag;
        }

        public DataTable GetAll()
        {
            DataTable Brand = null;
            try
            {
                Brand = _db.ExeSP_DataTable("select * from TblBrandPhone order by IDBrand asc", false, CommandType.Text);

            }
            catch (Exception ex)
            {
                throw ex;
            }
            return Brand;
        }

        public DataTable Delete(int IDBrand)
        {
            DataTable dt = null;
            try
            {
                dt = _db.ExeSP_DataTable("delete TblBrandPhone where IDBrand = @IDBrand ",
                    new string[] { "@IDBrand" },
                    new object[] { IDBrand }, CommandType.Text);

            }
            catch (Exception ex)
            {
                throw ex;
            }
            return dt;
        }
    }
}
